package com.wang.cloudstorage.db.dao;

import org.json.JSONException;
import org.json.JSONObject;

public interface INodeDAO {
	public final static int ACL_UNKNOWN = 0;

	// Lower 16 bits (Integer.SIZE/2) are reserved for denies.
	public final static int ACL_ALL_DENY = 1;
	public final static int ACL_READ_DENY = 1 << 1;
	public final static int ACL_WRITE_DENY = 1 << 2;

	// Upper 16 bits (Integer.SIZE/2) are reserved for allowed.
	public final static int ACL_ALL_ALLOWED = (1 << (Integer.SIZE/2-1));
	public final static int ACL_READ = (1 << Integer.SIZE/2);
	public final static int ACL_WRITE = (1 << (Integer.SIZE/2+1));
	
	public final static String KEY_INODE = "iNode";
	public final static String KEY_PERMISSION = "permissions";
	// Create is a sign only, not means it has specific privilege or permission.
	public final static String KEY_CREATOR = "creator";
	// Manager has all privileges and allowed to change other's permission.
	public final static String KEY_MANAGER = "administrators";
	public final static String KEY_VISIBLE = "visible";

	public final static int VISIBLE_SCOPE_INNER = 0;	// Default.
	/*
	 * The VISIBLE_SCOPE_INVISIBLE means totally invisible from client, 
	 * which is different to the attribute "hidden", which is only invisible by explorer.
	 * 
	 * At invisible file or folder is typically created by system for special usage,
	 * for example, file swapping, which is not allowed to be accessed from user at all.
	 */
	public final static int VISIBLE_SCOPE_INVISIBLE = 1;
	public final static int VISIBLE_SCOPE_INHERIT = 2;
	public final static int VISIBLE_SCOPE_DOMAIN = 3;
	public final static int VISIBLE_SCOPE_GLOBLE = 4;
	
	public final static int ATTRIBUTE_READ_ONLY	= 1;
	public final static int ATTRIBUTE_HIDDEN	= 1 << 1;
	
	/**
	 * 
	 * @return JSONObject.
	 * Format:
	 * {
	 * 	"iNode":			<inode_string>
	 * 	"creator":			creator_id
	 * 	"administrators":	{
	 * 							user_id_1
	 * 							user_id_2
	 * 						}
	 * 	"permissions":		{
	 * 							user_id_3:	xxxxxxxxxxxxxx
	 * 							user_id_4:	xxxxxxxxxxxxxxxx
	 * 						}
	 * 	"visible":			INNER | INHERT | GLOBLE | INVISIBLE
	 * 	"attributes":		READ_ONLY | HIDDEN
	 * }
	 * 
	 * @throws JSONException
	 */
	public JSONObject getACL() throws JSONException;
	public void deleteACL();
	public void createACL(String creator);
	
	public void updateAdministrators(Object administrators);
	
	public void createPermission(String permission);
	public void deletePermission(String userId) throws JSONException;
	public int getPermission(String userId) throws JSONException;
	public void updatePermission(Object permissions) throws JSONException;
}